<?php 
session_start(); // on relaye la session 
if(isset($_SESSION["is_registered"]) && $_SESSION["is_registered"] == "registered"){
		$enregistrer = $_SESSION["is_registered"];
}else{
	header("location:../../../menu.php"); // redirection en cas d'echec
}
require_once('../../../Connections/microassur.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
$colname_RS = "-1";
if (isset($_GET['Identifiant_agent'])) {
  $colname_RS = $_GET['Identifiant_agent'];
}
mysql_select_db($database_microassur, $microassur);
$query_RS = sprintf("SELECT * FROM agent WHERE Identifiant_agent = %s", GetSQLValueString($colname_RS, "int"));
$RS = mysql_query($query_RS, $microassur) or die(mysql_error());
$row_RS = mysql_fetch_assoc($RS);
$totalRows_RS = mysql_num_rows($RS);


  $updateSQL = sprintf("UPDATE agent SET Code_agent=%s, Nom_agent=%s, Prenom_agent=%s, Etat_agent=%s, Identifiant_unite=%s WHERE Identifiant_agent=%s",
                       GetSQLValueString($row_RS['Code_agent'], "text"),
                       GetSQLValueString($row_RS['Nom_agent'], "text"),
                       GetSQLValueString($row_RS['Prenom_agent'], "text"),
                       GetSQLValueString("I", "text"),
                       GetSQLValueString($row_RS['Identifiant_unite'], "int"),
                       GetSQLValueString($row_RS['Identifiant_agent'], "int"));

  mysql_select_db($database_microassur, $microassur);
  mysql_query("START TRANSACTION");
  $Result1 = mysql_query($updateSQL, $microassur) or die(mysql_error());

  if($Result1){ mysql_query("commit");header("Location: modagent.php?supp=success");}

else {mysql_query("rollback"); header("Location: modagent.php?supp=err&Identifiant_agent=".$colname_RS);}


mysql_free_result($RS);
?><p>&nbsp;</p>
